package com.wangshili.sys.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wangshili.common.exception.ServiceException;
import com.wangshili.sys.dao.SysRoleMenuDao;
import com.wangshili.sys.service.SysRoleMenuService;

@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {

	@Autowired
	private  SysRoleMenuDao sysMenuRolesDao;
	
	@Override
	public int deleteById(Integer id) {
		int rows = sysMenuRolesDao.deleteById(id);
		return rows;
	}

	@Override
	public int insertRoleMenu(Integer roleId, Integer... menuIds) {
		//1.先进行数据校验,角色id可以为空
		if(roleId==null || menuIds==null)throw new ServiceException("数据不能为空");
		int rows = 0 ;
		try {
			rows = sysMenuRolesDao.insertRoleMenu(roleId, menuIds);
			if (rows<1)throw new ServiceException("插入关系表失败，请重试");
			return rows;
		} catch (Exception e) {
			throw new ServiceException("插入关系表失败，请重试");//
		}
	}

}
